<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8" 
     import="java.util.List"
     import="java.util.ArrayList"
     import="java.util.Map"
     import="java.util.HashMap"
     import="dto.MItem"
     import="util.*"
     import="java.io.IOException"
     import="util.NetworkConfig"
     %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>welcome to ceat</title>
    <style type="text/css">
    	.container{
    		width:1000px;
    		margin:0 auto;
    	}
    	.type-bar{
    		width:1000px;
    		height:40px;
    	}
    	.type-a{
	        text-decoration:none;
	        line-height: 50px;
	        color: #000000;
	        padding:5px 10px;
    	}
    	.type-active{
    		font-weight: bold;
    	}
    	.main-table{
    		width:1000px;
    	}
    	th{
    		padding:0 30px;
    	}
    	table{
    		text-align: center;
    		margin: 10px auto;
    	}
    	
    	td{
    	border-radius:20px 20px 20px 20px;
    	border:2px solid #000;
    	width:auto;
    	 height:auto; 
    	 margin:auto;
    	 background-color:#fff;
    	 padding:20px;
    	}
    	
    </style>
  </head>
  <body>
	<jsp:include page="sec/common/mbar.jsp"></jsp:include>
	<div class="container">
		
		<form action="mlist" method="POST">
		
		<input type="text" name="searchName" value="${searchName}">
		<select name="searchId">
		   <c:forEach items="${foodtypes}" var ="t">
		       <c:if test="${curType == t.id}">
		       <option value=${t.id} selected>${t.name}</option>
		       </c:if>
		       <c:if test="${curType != t.id}">
		       <option value=${t.id}>${t.name}</option>
		       </c:if>
		   </c:forEach>
		</select>
		<input type="submit" name="submit" value="search"/>
		
		</form>
 
		
		<table>
		
			<%
			//List<MItem> mlist = null;
			//try{
			//	String res = UrlConnectionUtil.get(NetworkConfig.URL_ADMIN_GET_ALL_MUSER, null);
			//	mlist = JacksonUtil.fromJsonToArray(res, MItem.class);
			//}catch(IOException e){
			//	//A端崩溃了，重定向到错误页面
			//	response.sendRedirect("/ceat/error.html");
			//	return;
			//}

            
			List<MItem> mlist = (List<MItem>)session.getAttribute("mlist");
		
			
			
			if(mlist == null || mlist.isEmpty()){
				out.print("<p>没有找到符合条件的商家</p>");
			}
		
			int cur = 0;
			for(cur=0;cur<mlist.size();cur++){
		
				if(cur%4==0){
					out.print("<tr>");
				}
				MItem item = mlist.get(cur);
				out.print("<td><a href=\"foodlist?curmid="+ item.getId()+"&curname="+item.getStoreName()+"\"  target=\"_blank\">");
				out.print("<div>");
				
				out.print("<img style=\"width:120px;height:120px;\" src=\""+ item.getImg() +"\" ></img>");
				out.print("<p>");
				out.print(item.getStoreName());
				out.print("</p>");
				out.print("<p>");
				out.print(item.getAddress());
				out.print("</p>");
				out.print("</div>");
				out.print("</a></td>");
				
				if(cur%4==3){
					out.print("</tr>");
				}
			}
			%>	
		</table>
		
	</div>
  </body>
</html>